<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "country".
 *
 * @property integer $id
 * @property string $name
 * @property double $import_duty
 * @property double $export_tax
 * @property string $create_at
 * @property string $update_at
 *
 * @property Loan[] $loans
 * @property LoanRate[] $loanRates
 * @property Material[] $materials
 * @property News[] $news
 * @property User[] $users
 */
class Country extends \app\models\BaseModel {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'country';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['name', 'import_duty', 'export_tax'], 'required'],
            [['import_duty', 'export_tax'], 'number'],
            [['create_at', 'update_at'], 'safe'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => '国家名称',
            'import_duty' => '进口税',
            'export_tax' => '出口税',
            'create_at' => '创建时间',
            'update_at' => '更新时间',
        ];
    }

    public function fields() {
        $fields = [
            'id',
            'name',
            'import_duty',
            'export_tax',

            'loanRates',
        ];
        $fields = array_combine($fields, $fields);

        return $fields;
    }

    public function extraFields() {
        $fields = [
            'create_at',
            'update_at',
        ];
        $fields = array_combine($fields, $fields);
        return $fields;
    }

    public function getLoans() {
        return $this->hasMany(Loan::className(), ['country_id' => 'id'])->inverseOf('country');
    }

    public function getLoanRates() {
        return $this->hasMany(LoanRate::className(), ['country_id' => 'id'])->inverseOf('country');
    }

    public function getMaterials() {
        return $this->hasMany(Material::className(), ['country_id' => 'id'])->inverseOf('country');
    }

    public function getNews() {
        return $this->hasMany(News::className(), ['country_id' => 'id'])->inverseOf('country');
    }

    public function getUsers() {
        return $this->hasMany(User::className(), ['country_id' => 'id'])->inverseOf('country');
    }
}
